package cn.chen.controller;

import cn.chen.model.Department;
import cn.chen.service.DepartmentService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hbpu
 * @since 2023-05-28
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private UserController userController;

    //根据uid查询部门
    @GetMapping("/getDepartmentByUid")
    public Department getDepartmentByUid(Integer uid) {
        //根据uid查询部门id
        Integer did = userController.getUser(uid).getDid();

        LambdaQueryWrapper<Department> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Department::getId, did);
        return departmentService.getOne(wrapper);

    }

}
